<!-- 宿舍编号 -->
<template>
  <div class="app-container">
    <!-- 搜索 -->
      <searchForm
        :formOptions="formOptions"
        @onSearch="onSearch"
        :formLabelWidth="formLabelWidth"
        @onReset="onReset"
        v-show="showSearch"
      />
     
        <!-- <el-col :span="1.5">
              <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="oneAdd = true">一键新增</el-button>
            </el-col> -->
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      <el-table
        :data="tablelist"
        v-loading="loading"
      >
      <el-table-column
      type="index"
      label="序号"
      width="80"  align="center">
    </el-table-column>
        <el-table-column
          label="宿舍名称"
          prop="houseName"
          :show-overflow-tooltip="true"
          align="center"
        />
        <el-table-column label="宿舍编号" prop="houseNo" align="center" />
        <el-table-column label="电费宿舍编号" prop="dfNo" align="center">
        </el-table-column>
        <el-table-column
          label="操作"
          fixed="right"
          align="center"
          class-name="small-padding fixed-width"
          width="260"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['dorm:house:edit']"
              >修改</el-button
            >
            <!-- <el-button size="mini" type="text" @click="handleDelete(scope.row)">清空人员</el-button>
                <el-button size="mini" type="text" @click="handleDelete(scope.row)">设置角色</el-button> -->
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <el-dialog :title="title"  :visible.sync="open" width="40%" append-to-body @close="cancel">
      <el-form ref="form" :model="form" :rules="rules"  label-width="120px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="宿舍名称" prop="houseName">
              <el-input v-model="form.houseName" placeholder="请输入宿舍名称" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="宿舍编号" prop="houseNo">
              <el-input v-model="form.houseNo" placeholder="请输入宿舍编号" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="宿舍电费编号" prop="dfNo">
              <el-input v-model="form.dfNo" placeholder="请输入宿舍电费编号" />
            </el-form-item>
          </el-col>
        
        </el-row>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
      
      <script>
import searchForm from "@/components/Search/searchForm.vue";
import {houseList,houseEdit} from '@/api/apartment/apartmentBuilding'
export default {
  name: "Role",
  dicts: ["sys_charging_standards", "sys_room_type", ],
  components: {
    searchForm,
  },
  data() {
    return {
      formLabelWidth: "100px",
      formOptions: [
        {
          label: "宿舍名称",
          prop: "houseName",
          element: "el-input",
          placeholder: "请输入宿舍名称",
        },
        {
          label: "宿舍编号",
          prop: "houseNo",
          element: "el-input",
          placeholder: "请输入宿舍编号",
        },
        {
          label: "宿舍电费编号",
          prop: "dfNo",
          element: "el-input",
          placeholder: "请输入电费编号",
        },
      ],
      showType: 0,
      // 遮罩层
      loading: false,
      tablelist:[],
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      oneAdd: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        houseName: undefined,
        houseNo: undefined,
      },
      // 表单参数
      form: {
      
      },
      // 表单校验
      rules: {
        dfNo: [
          { required: true, message: "请输入宿舍电费编号", trigger: "blur" },
        ],
       
      },
     
    };
  },
  async created() {
  
    this.getList();

  },
  methods: {
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      houseList(this.queryParams).then((res) => {
        console.log(res)
        this.tablelist = res.rows
        this.total = res.total;
        this.loading = false;
      });
    },
    // 获取搜索表单提交的数据
    onSearch(val) {
      // 查询条件和分页数据合并
      const arr = Object.assign(this.queryParams, val);
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置
    onReset(data) {
      this.queryParams.pageNum = 1;
      const arr = Object.assign(this.queryParams, data);
      this.getList();
      this.$emit("searchHouse", data);
    },
    
    // 表单重置
    reset() {
      this.form = this.$options.data().form;
      // this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
 
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.form = { ...row };
      this.open = true;
      this.title = "修改信息";
    },
    cancel() {
      this.form = {}
      this.open = false
    },
     /** 提交按钮 */
     submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          // this.form.clrExamineStaffList = this.clrExamineStaffList;
         
          houseEdit( this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
        }
      });
    },
  },
};
</script>
      